package com.onexeor.particlesview;

import ohos.agp.render.Canvas;
import ohos.agp.render.Paint;
import ohos.agp.utils.Color;
import ohos.agp.utils.Point;

public class DotItem {
    private float size;

    private Point position;

    private int color;

    private Paint paint;

    private float speed;

    private float vx = 1;
    private float vy = 1;

    public DotItem() {
        init();
    }

    public DotItem(float size) {
        this.size = size;
        init();
    }

    DotItem(float size, Point position, int color) {
        this.size = size;
        this.position = position;
        this.color = color;
        init();
    }

    DotItem(float size, Point position, int color, float speed) {
        this.speed = speed;
        this.size = size;
        this.position = position;
        this.color = color;
        init();
    }

    private void init() {
        initPaint();
        initPoint();
    }

    private void initPaint() {
        paint = new Paint();
        paint.setAntiAlias(true);
        paint.setSubpixelAntiAlias(true);
        paint.setColor(new Color(color));
        paint.setAntiAlias(true);
    }

    private void initPoint() {
        if (position == null) {
            position = new Point();
        }
    }

    public float getSpeed() {
        return speed;
    }

    /**
     * set Position
     * @param xx double
     * @param yy double
     */
    public void setPosition(double xx, double yy) {
        this.position.modify((float) xx, (float) yy);
    }

    public Point getPosition() {
        return position;
    }

    public void setSpeed(float speed) {
        this.speed = speed;
    }

    public float getVx() {
        return vx;
    }

    public void setVx(float vx) {
        this.vx = vx;
    }

    public float getVy() {
        return vy;
    }

    public void setVy(float vy) {
        this.vy = vy;
    }

    public void setSize(float size) {
        this.size = size;
    }

    public void setPosition(Point position) {
        if (this.position != null) {
            this.position.modify(position);
        } else {
            this.position = position;
        }
    }

    public void setPaint(Paint paint) {
        this.paint = paint;
    }

    public float getSize() {
        return size;
    }

    void render(Canvas canvas) {
        if (canvas != null) {
            canvas.drawCircle(position.getPointX(), position.getPointY(), size, paint);
        }
    }

    public void setColor(int color) {
        this.color = color;
        initPaint();
    }
}
